<?php
/** ***********************
 * 作者：Zpy
 * 日期：2015/5/21
 * 作用：数据模型
 ** ***********************/
class centerModelHome extends coreFrameworkModel {
	function test(){
		//默认的数据库源
		$sql=SqlToolsClass::SelectItem("admin");
		$datas=$this->GetAll($sql);
		
		//切换数据库源
		/*$sql=SqlToolsClass::SelectItem("activities_company_bind");
		$datas=$this->GetRow($sql,"test");*/
		
		//切换回默认的数据源
		$sql=SqlToolsClass::SelectItem("admin");
		$datas=$this->GetAll($sql);
	}
	
	function getTicketInfo($number){
		$join = ' left join '.SqlToolsClass::getTableName('business').' b on b.id=t.shop_id';
		$sql = SqlToolsClass::SelectItem('ticket as t','t.number="'.$number.'"','t.*,b.business_name',$join);
		return $this->GetRow($sql);
	}
	function updateTicket($number,$data){
		$sql=SqlToolsClass::EditData("ticket", $data,"number=".$number);
		return $this->Execute($sql);
	}
	//获取商户列表
	function getBusShopByChannelId($where)
	{
		$where = implode(' and ',$where);
		
		$sql=SqlToolsClass::SelectItem("business",$where,'*',null,'id desc');
		return $this->createPage($sql,'homePage');
	}
    //获取商户详细信息
    function getBusShopById($id)
    {
        $sql=SqlToolsClass::SelectItem("business",'id='.$id,'*',null,'id desc');
        return $this->GetRow($sql);
    }
	//获取渠道应用列表
	function getChannelApp($id)
	{
		$sql=SqlToolsClass::SelectItem("channel_app","channel_id=$id",'*',null,'id desc');
		return $this->createPage($sql,'homePage');
	}
    //保存商家
    function saveBusiness($data,$id){
        if ($id) {
            $sql = SqlToolsClass::EditData('business',$data,'id='.$id);
        }else{
            $sql = SqlToolsClass::InsertData('business',$data);
        }
        return $this->Execute($sql);
    }
	//获取商户名称
	function getBusinessName($id)
	{
		$sql=SqlToolsClass::SelectItem("business","id in($id)",'business_name',null);
		return $this->GetAll($sql);
	}

    //保存应用
    function saveChannelApp($data,$id)
    {
        if ($id) {
            $sql = SqlToolsClass::EditData('channel_app',$data,'id='.$id);
        }else{
            $sql = SqlToolsClass::InsertData('channel_app',$data);

        }
        return $this->Execute($sql);
    }
	//获取商户列表不分页
	function getBusShopByChannelIdNoPage($channel_id)
	{
		$sql=SqlToolsClass::SelectItem("business",'channel_id='.$channel_id,'*',null,'id desc');
		return $this->GetAll($sql);
	}
	//获取发票列表
	function getTicketList($where){
		$where = implode(' and ',$where);
		$sql = SqlToolsClass::SelectItem('ticket',$where);

		return $this->createPage($sql,'homePage');
	}
    //获取应用信息
    function getChannelAppById($id)
    {
        //$join = ' left join '.SqlToolsClass::getTableName('business').' b on b.id = t.shop_id';
        //$sql=SqlToolsClass::SelectItem("channel_app as t","t.shop_id=$id",'t.price,t.status,t.c_time,b.business_name,t.number',$join,'t.id desc');
        $sql=SqlToolsClass::SelectItem("channel_app",'id='.$id,'*',null,'id desc');
        return $this->GetRow($sql);
    }

    function binding_use($app_data)
    {
        /*if($app_data)
        {
            $str =  "or id in($app_data)";
        }
        $sql=SqlToolsClass::SelectItem("business","author_status=1 ".$str,'*',null,'id desc');
        return $this->GetAll($sql);*/
        $sql=SqlToolsClass::SelectItem("business","channel_id=$app_data",'*',null,'id desc');
        return $this->GetAll($sql);

    }
    //获取地区   省
    function getProvinceList($post)
    {
        if($post){
            $area='parentid='.$post['parentid'];
        }else{
            $area="parentid=0";
        }
        $sql=SqlToolsClass::SelectItem("area",$area,'*',null);
        return $this->GetAll($sql);
    }
    //获取地区名称
    function getAreaCitynameByCodeid($codeid)
    {
        $sql=SqlToolsClass::SelectItem("area",'codeid='.$codeid,'cityName',null);
        $cityName = $this->GetRow($sql);
        return $cityName['cityName'];
    }
	//创建待开发票
	function createTicket($data){
		$sql = SqlToolsClass::InsertData('ticket',$data);
		return $this->Execute($sql);
	}
	//增加商品信息
	function insertTicketGoods($datas){
		$sql = SqlToolsClass::InsertDatas('ticket_goods',$datas);
		return $this->Execute($sql);
	}
	//保存用户信息
	function saveUser($data,$where){
		$where = implode(' and ',$where);
		$sql = SqlToolsClass::EditData('channel_user',$data,$where);
		return  $this->Execute($sql);
	}
	//获取用户信息
	function getUserInfo($id){
		$sql = SqlToolsClass::SelectItem('channel_user','id='.$id);
		return $this->GetRow($sql);
	}
	//验证密码
	function checkPassword($pwd,$id){
		$sql = SqlToolsClass::SelectItem('channel_user',"id=".$id." and password='".md5(md5($pwd))."'");
		return $this->GetRow($sql);
	}
	//修改密码
	function savePassword($pwd,$id){
		$sql = SqlToolsClass::EditData('channel_user',array('password'=>md5(md5($pwd))),'id='.$id);
		
		return $this->Execute($sql);
	}
	
	
	
}
?>